package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.client.ItemFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 *
 * Item管理 controller组件
 * @author zjiajia
 * @date 2021/1/31 10:49
 */

@Controller
public class ItemController {
    /**
     * item feign调用接口
     */
    @Autowired
    private ItemFeignClient itemFeignClient;

    /**
     * 请求商品详情页
     * @param skuId skuId
     * @param model model
     * @return      返回模板界面
     */
    @RequestMapping("{skuId}.html")
    public String getItem(@PathVariable Long skuId , Model model){
        Result<Map> item = itemFeignClient.getItem(skuId);

        model.addAllAttributes(item.getData());
        return "item/index";
    }


}
